//package org.ytor.core.querygen.querygen.old;
//
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import jakarta.servlet.http.HttpServletRequest;
//import org.ytor.core.querygen.token.QueryTokenizer;
//import org.ytor.core.querygen.token.Token;
//import org.ytor.core.util.ReqUtil;
//import org.ytor.core.util.SpringUtil;
//import org.springframework.context.ApplicationContext;
//import org.springframework.core.Ordered;
//
//import java.util.Arrays;
//import java.util.Comparator;
//import java.util.List;
//import java.util.Map;
//
///**
// * created by yangtong on 2025/4/7 16:04:54
// * <br/>
// * QueryWrapper生成器
// */
//public class QueryWrapperGenerate {
//
//    private static List<AbsQueryCondition> conditions;
//    /**
//     * 忽略请求中的这些字段
//     */
//    private static final List<String> ignoreFields = List.of("pageNo", "pageSize");
//
//    public static <T> QueryWrapper<T> init(Object entity) {
//        HttpServletRequest request = ReqUtil.getRequest();
//        String queryString = null;
//        if (request != null) {
//            queryString = request.getQueryString();
//        }
//        QueryWrapper<T> queryWrapper = new QueryWrapper<>();
//        if (queryString != null) {
//            List<Token> tokens = Arrays.stream(queryString.split("&")).filter(i -> {
//                String key = i.split("=")[0];
//                return !ignoreFields.contains(key);
//            }).map(QueryTokenizer::tokenize).toList();
//
//            for (Token token : tokens) {
//                for (AbsQueryCondition queryCondition : getConditions()) {
//                    if (queryCondition.isMatch(token)) {
//                        queryCondition.genQueryWrapper(queryWrapper, token);
//                        break;
//                    }
//                }
//            }
//        }
//
//        return queryWrapper;
//    }
//
//    private static List<AbsQueryCondition> getConditions() {
//        if (conditions == null) {
//            ApplicationContext context = SpringUtil.getApplicationContext();
//            Map<String, AbsQueryCondition> queryConditions = context.getBeansOfType(AbsQueryCondition.class);
//            conditions = queryConditions.values().stream().sorted(Comparator.comparingInt(Ordered::getOrder)).toList();
//        }
//        return conditions;
//    }
//
//}
